package com.bj58.groupbuy.action.controllers;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import javax.servlet.http.HttpServletRequest;
import org.springframework.web.bind.ServletRequestUtils;

import com.bj58.groupbuy.action.model.ClickCityVo;
import com.bj58.groupbuy.action.model.ClickEventsSourceVo;
import com.bj58.groupbuy.action.model.ConflictDelectVo;
import com.bj58.groupbuy.action.model.TrackURLToPVUVVo;
import com.bj58.groupbuy.action.model.UrlToPvUvVo;
import com.bj58.groupbuy.action.service.StatisticsPlanService;
import com.bj58.groupbuy.action.util.DateUtil;
import com.bj58.groupbuy.action.util.ExcelUtil2;
import com.bj58.groupbuy.action.util.HbaseUtil;
import com.bj58.groupbuy.service.locator.ServiceLocator;
import com.bj58.groupbuy.wf.page.Paginate;
import com.bj58.wf.mvc.ActionResult;
import com.bj58.wf.mvc.BeatContext.Model;
import com.bj58.wf.mvc.MvcController;
import com.bj58.wf.mvc.actionresult.ContentResult;
import com.bj58.wf.mvc.annotation.GET;
import com.bj58.wf.mvc.annotation.POST;
import com.bj58.wf.mvc.annotation.Path;

/**
 * 统计规划与数据查询
 * 
 * @author houzuoxin
 */
@Path("Statistics")
public class StatisticsPlanController extends MvcController {
	private final StatisticsPlanService statisticsPlanService = ServiceLocator
			.get(StatisticsPlanService.class);

	/**
	 * 主界面入口
	 * 
	 * @author houzuoxin
	 * */
	@Path("StatisticsMain")
	@POST
	@GET
	public ActionResult StatisticsMain() {

		return ActionResult.view("/Statistics/StatisticsMain");

	}

	/**
	 * URL查询量
	 * 
	 * @author houzuoxin
	 * @return
	 */
	@Path("UrlToPvUvBi")
	@POST
	@GET
	public ActionResult UrlToPvUvBiData() {
		HttpServletRequest request = beat.getRequest();
		Model model = beat.getModel();
		try {
			/** 获取日期 */
			String StartDate = ServletRequestUtils.getStringParameter(request,
					"startDate", "");
			String EndDate = ServletRequestUtils.getStringParameter(request,
					"endDate", "");
			String platname = ServletRequestUtils.getStringParameter(request,
					"platform", "");
			/** 获取查询方式 */
			String queryway = ServletRequestUtils.getStringParameter(request,
					"queryway", "");
			String selecttype = ServletRequestUtils.getStringParameter(request,
					"typename", "");
			/** 获取url */
			String URLname = ServletRequestUtils.getStringParameter(request,
					"URLname", "");
			//获取日期维度
			String statCombine = ServletRequestUtils.getStringParameter(
					request, "statCombine", "");
			/** 获取页码 */
			int pageindex = ServletRequestUtils.getIntParameter(request,
					"pageindex", 1);// 页数。
			List<String> cols = new ArrayList<String>();
			String excelTitle = "流量页面查询数据";
			StringBuffer url = new StringBuffer();// 分页的URL
			url.append("&startDate=" + StartDate);
			url.append("&endDate=" + EndDate);
			url.append("&queryway=" + queryway);
			url.append("&URLname=" + URLname);
			url.append("&typename=" + selecttype);
			url.append("&platform=" + platname);
			url.append("&statCombine=" + statCombine);
			if(!"".equals(statCombine))
			{
				cols.add("statdate");
			}
			cols.add("urlsource");
			cols.add("url_pv");
			cols.add("url_uv");
			List<UrlToPvUvVo> resultlist = new ArrayList<UrlToPvUvVo>();
			model.add("startDate", StartDate);
			model.add("endDate", EndDate);
			model.add("URLname", URLname);
			model.add("statCombine", statCombine);
			if ("".equals(platname)) {
				model.add("platform", "PC");
			} else {
				model.add("platform", platname);
			}

			if ("".equals(queryway))
				model.add("queryway", "jingque");
			else
				model.add("queryway", queryway);
			if ("".equals(StartDate) || "".equals(EndDate)) {
				return ActionResult.view("/Statistics/UrlToPvUvBi");
			}
			List<String> dateList = DateUtil.getDayList(StartDate, EndDate);
			List<String> rowKeyList = statisticsPlanService
					.generateRowKeyPrefixListForBi(dateList, URLname, platname);
			Map<String, Map<String, Object>> resultMap = null;
			if (queryway.equals("qianzhui")) {
				resultMap = statisticsPlanService.QueryForListByPrefix(
						rowKeyList, "ZhUrlToPvUvHBase",statCombine);
			} else if (queryway.equals("jingque")) {
				resultMap = statisticsPlanService.QueryForListByKey(rowKeyList,
						"ZhUrlToPvUvHBase",statCombine);
			}
			resultlist = statisticsPlanService.DataInJson(resultMap);
			if ("".equals(selecttype))// 查询
			{
				Paginate<String> pList = new Paginate<String>(
						resultlist.size(), pageindex, 20, null);
				model.add("pList", pList);
				model.add("paramurl", url.toString());
				List<UrlToPvUvVo> rslist = new ArrayList<UrlToPvUvVo>();
				for (int i = (pageindex - 1) * 20; i < resultlist.size()
						&& i < pageindex * 20; i++) {
					rslist.add(resultlist.get(i));
				}
				model.add("rsList", rslist);
			} else // 下载
			{
				ExcelUtil2<UrlToPvUvVo> u = new ExcelUtil2<UrlToPvUvVo>(
						UrlToPvUvVo.class);
				u.setFieldFilter(cols);
				u.createExcelFileAndDownload(resultlist, excelTitle);
				return new ContentResult("");
			}
		} catch (Exception e) {
			e.printStackTrace();
			return new ContentResult("error");
		}
		return ActionResult.view("/Statistics/UrlToPvUvBi");
	}

	/**
	 * pagetype查流量
	 * 
	 * @author houzuoxin
	 * @return
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Path("TrackURLtoPVUV")
	@POST
	@GET
	public ActionResult TrackURLtoPVUVBiData() {
		HttpServletRequest request = beat.getRequest();
		Model model = beat.getModel();
		try {
			/** 获取日期 */
			String StartDate = ServletRequestUtils.getStringParameter(request,
					"startDate", "");
			String EndDate = ServletRequestUtils.getStringParameter(request,
					"endDate", "");
			String platname = ServletRequestUtils.getStringParameter(request,
					"platform", "");
			/** 获取查询条件 */
			String pagetype = ServletRequestUtils.getStringParameter(request,
					"pagetype", "");
			String page = ServletRequestUtils.getStringParameter(request,
					"page", "");
			String area = ServletRequestUtils.getStringParameter(request,
					"area", "");
			String cate1 = ServletRequestUtils.getStringParameter(request,
					"cate1", "");
			String cate2 = ServletRequestUtils.getStringParameter(request,
					"cate2", "");
			String selecttype = ServletRequestUtils.getStringParameter(request,
					"typename", "");
			//获取日期维度
			String statCombine = ServletRequestUtils.getStringParameter(
					request, "statCombine", "");
			/** 获取页码 */
			int pageindex = ServletRequestUtils.getIntParameter(request,
					"pageindex", 1);// 页数。
			if ("".equals(StartDate) || "".equals(EndDate)) {
				model.add("pagetype", "ALL");
				model.add("page", "ALL");
				model.add("area", "ALL");
				model.add("cate1", "ALL");
				model.add("cate2", "ALL");
				model.add("platform", "PC");
				return ActionResult.view("/Statistics/TrackURLtoPVUV");
			}
			model.add("pagetype", pagetype);
			model.add("page", page);
			model.add("area", area);
			model.add("cate1", cate1);
			model.add("cate2", cate2);
			List<String> cols = new ArrayList<String>();
			String excelTitle = "流量页面查询数据";
			StringBuffer url = new StringBuffer();// 分页的URL
			url.append("&startDate=" + StartDate);
			url.append("&endDate=" + EndDate);
			url.append("&typename=" + selecttype);
			url.append("&platform=" + platname);
			url.append("&statCombine=" + statCombine);
			url.append("&pagetype=" + pagetype);
			url.append("&page=" + page);
			url.append("&area=" + area);
			url.append("&cate1=" + cate1);
			url.append("&cate2=" + cate2);
			if(!"".equals(statCombine))
			{
				cols.add("statdate");
			}
			cols.add("pagetype");
			cols.add("page");
			cols.add("area");
			cols.add("cate1");
			cols.add("cate2");
			cols.add("url_pv");
			cols.add("url_uv");
			cols.add("newuv");
			List<TrackURLToPVUVVo> resultlist = new ArrayList<TrackURLToPVUVVo>();
			model.add("startDate", StartDate);
			model.add("endDate", EndDate);
			model.add("statCombine", statCombine);
			if ("".equals(platname)) {
				model.add("platform", "PC");
			} else {
				model.add("platform", platname);
			}
			
			List<String> dateList = DateUtil.getDayList(StartDate, EndDate);
			List<String> keyresultList = new ArrayList<String>();
			Map rowKey = new TreeMap();
			for (String dateString : dateList) {
				rowKey.put("00", dateString);
				rowKey.put("01", platname);
				rowKey.put("02", pagetype);
				rowKey.put("03", page);
				rowKey.put("04", area);
				rowKey.put("05", cate1);
				rowKey.put("06", cate2);
				keyresultList.add(HbaseUtil.RowKeyToString((TreeMap) rowKey));
			}
			Map<String, Map<String, Object>> resultMap = null;

			resultMap = statisticsPlanService.QueryForListByKeyForTrack(
					keyresultList, "ZhTrackURLtoPVUV",statCombine);
			resultlist = statisticsPlanService.DataInJsonForTrack(resultMap);
			if ("".equals(selecttype))// 查询
			{
				Paginate<String> pList = new Paginate<String>(
						resultlist.size(), pageindex, 20, null);
				model.add("pList", pList);
				model.add("paramurl", url.toString());
				List<TrackURLToPVUVVo> rslist = new ArrayList<TrackURLToPVUVVo>();
				for (int i = (pageindex - 1) * 20; i < resultlist.size()
						&& i < pageindex * 20; i++) {
					rslist.add(resultlist.get(i));
				}
				model.add("rsList", rslist);
			} else // 下载
			{
				ExcelUtil2<TrackURLToPVUVVo> u = new ExcelUtil2<TrackURLToPVUVVo>(
						TrackURLToPVUVVo.class);
				u.setFieldFilter(cols);
				u.createExcelFileAndDownload(resultlist, excelTitle);
				return new ContentResult("");
			}
		} catch (Exception e) {
			e.printStackTrace();
			return new ContentResult("error");
		}
		return ActionResult.view("/Statistics/TrackURLtoPVUV");
	}

	/**
	 * 导流-落地页查询
	 * 
	 * @author houzuoxin
	 * @return
	 */
	@Path("ClickEventsSource")
	@POST
	@GET
	public ActionResult ClickEventsSourceData() {
		HttpServletRequest request = beat.getRequest();
		Model model = beat.getModel();
		try {
			/** 获取日期 */
			String StartDate = ServletRequestUtils.getStringParameter(request,
					"startDate", "");
			String EndDate = ServletRequestUtils.getStringParameter(request,
					"endDate", "");

			String platname = ServletRequestUtils.getStringParameter(request,
					"platform", "");
			/** 获取查询条件 */
			String PageTypeCombine = ServletRequestUtils.getStringParameter(
					request, "PageTypeCombine", "");
			String TwoPageTypeCombine = ServletRequestUtils.getStringParameter(
					request, "TwoPageTypeCombine", "");
			String cateOneCombine = ServletRequestUtils.getStringParameter(
					request, "cateOneCombine", "");
			String cateTwoCombine = ServletRequestUtils.getStringParameter(
					request, "cateTwoCombine", "");
			String PvIndex = ServletRequestUtils.getStringParameter(request,
					"PvIndex", "");
			String UvIndex = ServletRequestUtils.getStringParameter(request,
					"UvIndex", "");
			String sourcename = ServletRequestUtils.getStringParameter(request,
					"sourcename", "");
			/** 获取查询方式 */
			String selecttype = ServletRequestUtils.getStringParameter(request,
					"typename", "");
			/** 获取页码 */
			int pageindex = ServletRequestUtils.getIntParameter(request,
					"pageindex", 1);// 页数。
			List<String> cols = new ArrayList<String>();
			cols.add("statdate");
			cols.add("sourcename");
			String excelTitle = "带来落地页流量数据";
			StringBuffer url = new StringBuffer();// 分页的URL
			if ("".equals(StartDate) || "".equals(EndDate)) {
				model.add("platform", "58PC");
				return ActionResult.view("/Statistics/ClickEventsSource");
			}
			if ("".equals(platname)) {
				model.add("platform", "58PC");
			} else {
				model.add("platform", platname);
			}
			model.add("startDate", StartDate);
			model.add("endDate", EndDate);
			model.add("sourcename", sourcename);
			url.append("&startDate=" + StartDate);
			url.append("&endDate=" + EndDate);
			url.append("&platform=" + platname);
			HashSet<String> wdzbSet = new HashSet<String>();
			if (!"".equals(PageTypeCombine)) {
				model.add("PageTypeCombine", PageTypeCombine);
				url.append("&PageTypeCombine=" + PageTypeCombine);
				cols.add("pagetype");
				wdzbSet.add("PageTypeCombine");
			}
			if (!"".equals(TwoPageTypeCombine)) {
				model.add("TwoPageTypeCombine", TwoPageTypeCombine);
				url.append("&TwoPageTypeCombine=" + TwoPageTypeCombine);
				cols.add("twopagetype");
				wdzbSet.add("TwoPageTypeCombine");
			}
			if (!"".equals(cateOneCombine)) {
				model.add("cateOneCombine", cateOneCombine);
				url.append("&cateOneCombine=" + cateOneCombine);
				cols.add("cate1");
				wdzbSet.add("cateOneCombine");
			}
			if (!"".equals(cateTwoCombine)) {
				model.add("cateTwoCombine", cateTwoCombine);
				url.append("&cateTwoCombine=" + cateTwoCombine);
				cols.add("cate2");
				wdzbSet.add("cateTwoCombine");
			}
			if (!"".equals(PvIndex)) {
				model.add("PvIndex", PvIndex);
				url.append("&PvIndex=" + PvIndex);
				cols.add("pv");
				wdzbSet.add("PvIndex");
			}
			if (!"".equals(UvIndex)) {
				model.add("UvIndex", UvIndex);
				url.append("&UvIndex=" + UvIndex);
				cols.add("uv");
				wdzbSet.add("UvIndex");
			}
			url.append("&sourcename=" + sourcename);
			List<ClickEventsSourceVo> resultlist = new ArrayList<ClickEventsSourceVo>();
			List<String> dateList = DateUtil.getDayList(StartDate, EndDate);
			List<String> keyresultList = new ArrayList<String>();
			for (String date : dateList) {
				String rowkeyPrefix = date + "::" + platname + "::"
						+ sourcename;
				keyresultList.add(rowkeyPrefix);
			}

			resultlist = statisticsPlanService
					.QueryForListByPrefixForClickEvent("ZhSourcePvUv",
							keyresultList, wdzbSet, 100);
			if ("".equals(selecttype))// 查询
			{
				Paginate<String> pList = new Paginate<String>(
						resultlist.size(), pageindex, 20, null);
				model.add("pList", pList);
				model.add("paramurl", url.toString());
				List<ClickEventsSourceVo> rslist = new ArrayList<ClickEventsSourceVo>();
				for (int i = (pageindex - 1) * 20; i < resultlist.size()
						&& i < pageindex * 20; i++) {
					rslist.add(resultlist.get(i));
				}
				model.add("rsList", rslist);
			} else // 下载
			{
				resultlist = statisticsPlanService
						.QueryForListByPrefixForClickEvent("ZhSourcePvUv",
								keyresultList, wdzbSet, 5000);
				ExcelUtil2<ClickEventsSourceVo> u = new ExcelUtil2<ClickEventsSourceVo>(
						ClickEventsSourceVo.class);
				u.setFieldFilter(cols);
				u.createExcelFileAndDownload(resultlist, excelTitle);
				return new ContentResult("");
			}
		} catch (Exception e) {
			e.printStackTrace();
			return new ContentResult("error");
		}
		return ActionResult.view("/Statistics/ClickEventsSource");
	}

	/**
	 * 来源-落地页查询
	 * 
	 * @author houzuoxin
	 * @return
	 */
	/*
	 * @Path("ClickEventsSource")
	 * 
	 * @Check
	 * 
	 * @POST
	 * 
	 * @GET public ActionResult ClickEventsSourceData() { HttpServletRequest
	 * request = beat.getRequest(); Model model = beat.getModel(); try {
	 *//** 获取日期 */
	/*
	 * String StartDate = ServletRequestUtils.getStringParameter(request,
	 * "startDate", ""); String EndDate =
	 * ServletRequestUtils.getStringParameter(request, "endDate", "");
	 * 
	 * String platname = ServletRequestUtils.getStringParameter(request,
	 * "platform", "");
	 *//** 获取查询方式 */
	/*
	 * String selecttype = ServletRequestUtils.getStringParameter(request,
	 * "selecttype", ""); //查询下载类型 String
	 * downtype=ServletRequestUtils.getStringParameter(request, "downtype", "");
	 *//** 获取页码 */
	/*
	 * int pageindex = ServletRequestUtils.getIntParameter(request, "pageindex",
	 * 1);// 页数。 List<String> cols = new ArrayList<String>(); StringBuffer url =
	 * new StringBuffer();// 分页的URL List<DisplayLocal> citynamelist=new
	 * ArrayList<DisplayLocal>();
	 * citynamelist=displaylocalService.getLevelOne(); List<String> cityname =
	 * new ArrayList<String>(); for(int i=0;i<citynamelist.size();i++) {
	 * cityname.add(citynamelist.get(i).getLocalName()); }
	 * model.add("cityList",cityname); model.add("filecity","北京");
	 * ArrayList<String> catename=new ArrayList<String>(); List<DisplayCate>
	 * tempcatelist=new ArrayList<DisplayCate>();
	 * tempcatelist=displayCateService.getAllLevelOne(); List<String>
	 * rowKeyList=new ArrayList<String>();//获取rowkey for(int
	 * i=0;i<tempcatelist.size();i++) {
	 * catename.add(tempcatelist.get(i).getCateName()); }
	 * model.add("businessList",catename); model.add("filebusiness","全职招聘");
	 * model.add("startDate", StartDate); model.add("endDate", EndDate);
	 * url.append("&startDate=" + StartDate); url.append("&endDate=" + EndDate);
	 * url.append("&selecttype=" + selecttype); if ("".equals(platname)) {
	 * model.add("platform", "PC"); } else { model.add("platform", platname); }
	 * url.append("&platform=" + platname); if ("".equals(StartDate) ||
	 * "".equals(EndDate)) { return
	 * ActionResult.view("/Statistics/ClickEventsSource"); } List<String>
	 * dateList = DateUtil.getDayList(StartDate, EndDate); //获取rowkeylist
	 * if("detailquery".equals(selecttype)) { String cateid=""; String
	 * cityid=""; String
	 * catenameString=ServletRequestUtils.getStringParameter(request,
	 * "filebusiness", ""); String
	 * citynameString=ServletRequestUtils.getStringParameter(request,
	 * "filecity", ""); //根据对应的业务线，城市，获取相应的id for(int
	 * i=0;i<tempcatelist.size();i++) {
	 * if(catenameString.equals(tempcatelist.get(i).getCate1())) {
	 * cateid=String.valueOf(tempcatelist.get(i).getCate1ID());
	 * 
	 * } } for(int i=0;i<citynamelist.size();i++) {
	 * if(citynameString.equals(citynamelist.get(i).getLocalName())) {
	 * cityid=String.valueOf(citynamelist.get(i).getLocalId());
	 * 
	 * } } String pageSign=ServletRequestUtils.getStringParameter(request,
	 * "pagetype", ""); String
	 * pagename=ServletRequestUtils.getStringParameter(request, "pagename", "");
	 * for(String dateString:dateList){ String rowKey=""; rowKey+= dateString;
	 * rowKey+="|"; rowKey+= platname; rowKey+="|"; if(pageSign.equals(""))
	 * pageSign="0"; rowKey+= pageSign; rowKey+="|"; if(pagename.equals(""))
	 * pagename="0"; rowKey+= pagename; rowKey+="|"; if(!cityid.equals("")){
	 * rowKey+= cityid; rowKey+="|"; if(!cateid.equals("")){ rowKey+=cateid;
	 * rowKey+="|"; } }else{ if(!cateid.equals("")){ rowKey+="0|";
	 * rowKey+=cateid; rowKey+="|"; } } rowKeyList.add(rowKey); }
	 * url.append("&filebusiness=" + catenameString); url.append("&filecity=" +
	 * citynameString); url.append("&pagetype=" + pageSign);
	 * url.append("&pagename=" + pagename); }else { String
	 * sourcename=ServletRequestUtils.getStringParameter(request, "sourcename",
	 * ""); for(String dateString:dateList){ String rowKey=""; rowKey+=
	 * dateString; rowKey+="|"; rowKey+= platname; rowKey+="|"; rowKey+=
	 * sourcename; rowKeyList.add(rowKey); } url.append("&sourcename=" +
	 * sourcename); model.add("sourcename", sourcename); } String excelTitle =
	 * "来源-落地页查询"; cols.add("sourcetype"); cols.add("cate"); cols.add("city");
	 * cols.add("page"); cols.add("pagetype"); cols.add("url_pv");
	 * cols.add("url_uv"); List<ClickEventsSourceVo> resultlist = new
	 * ArrayList<ClickEventsSourceVo>(); Map<String, Map<String, Object>>
	 * resultMap = null; resultMap =
	 * statisticsPlanService.QueryForListByPrefixForClickEvent(rowKeyList,
	 * "ZhSourcePvUv"); resultlist =
	 * statisticsPlanService.DataInJsonForClickEvents(resultMap); if
	 * ("".equals(downtype))// 查询 { Paginate<String> pList = new
	 * Paginate<String>( resultlist.size(), pageindex, 20, null);
	 * model.add("pList", pList); model.add("paramurl", url.toString());
	 * List<ClickEventsSourceVo> rslist = new ArrayList<ClickEventsSourceVo>();
	 * for (int i = (pageindex - 1) * 20; i < resultlist.size() && i < pageindex
	 * * 20; i++) { rslist.add(resultlist.get(i)); } model.add("rsList",
	 * rslist); } else // 下载 { ExcelUtil2<ClickEventsSourceVo> u = new
	 * ExcelUtil2<ClickEventsSourceVo>( ClickEventsSourceVo.class);
	 * u.setFieldFilter(cols); u.createExcelFileAndDownload(resultlist,
	 * excelTitle); return new ContentResult(""); } } catch (Exception e) {
	 * e.printStackTrace(); return new ContentResult("error"); } return
	 * ActionResult.view("/Statistics/ClickEventsSource"); }
	 */
	/**
	 * 点击量查询
	 * 
	 * @author houzuoxin ok
	 * @return
	 */
	@Path("ClickCity")
	@POST
	@GET
	public ActionResult Click_CityBiData() {
		HttpServletRequest request = beat.getRequest();
		Model model = beat.getModel();
		try {
			/** 获取日期 */
			String StartDate = ServletRequestUtils.getStringParameter(request,
					"startDate", "");
			String EndDate = ServletRequestUtils.getStringParameter(request,
					"endDate", "");
			String platname = ServletRequestUtils.getStringParameter(request,
					"platform", "");
			/** 获取查询条件 */
			String cityCombine = ServletRequestUtils.getStringParameter(
					request, "cityCombine", "");
			String clickcountIndex = ServletRequestUtils.getStringParameter(
					request, "clickcountIndex", "");
			String clickpeopleIndex = ServletRequestUtils.getStringParameter(
					request, "clickpeopleIndex", "");
			String clicktag = ServletRequestUtils.getStringParameter(request,
					"clicktag", "");
			String selecttype = ServletRequestUtils.getStringParameter(request,
					"typename", "");
			/** 获取页码 */
			int pageindex = ServletRequestUtils.getIntParameter(request,
					"pageindex", 1);// 页数。
			if ("".equals(StartDate) || "".equals(EndDate)) {
				model.add("platform", "58PC");
				return ActionResult.view("/Statistics/ClickCity");
			}
			model.add("clicktag", clicktag);
			List<String> cols = new ArrayList<String>();
			String excelTitle = "点击量查询数据";
			StringBuffer url = new StringBuffer();// 分页的URL
			url.append("&startDate=" + StartDate);
			url.append("&endDate=" + EndDate);
			url.append("&platform=" + platname);
			HashSet<String> wdzbSet = new HashSet<String>();
			if (!"".equals(cityCombine)) {
				model.add("cityCombine", cityCombine);
				url.append("&cityCombine=" + cityCombine);
				cols.add("city");
				wdzbSet.add("cityCombine");
			}
			if (!"".equals(clickcountIndex)) {
				model.add("clickcountIndex", clickcountIndex);
				url.append("&clickcountIndex=" + clickcountIndex);
				cols.add("clickcount");
				wdzbSet.add("clickcountIndex");
			}
			if (!"".equals(clickpeopleIndex)) {
				model.add("clickpeopleIndex", clickpeopleIndex);
				url.append("&clickpeopleIndex=" + clickpeopleIndex);
				cols.add("clickpeople");
				wdzbSet.add("clickpeopleIndex");
			}
			url.append("&clicktag=" + clicktag);
			cols.add("statdate");
			cols.add("clicktag");
			List<ClickCityVo> resultlist = new ArrayList<ClickCityVo>();
			model.add("startDate", StartDate);
			model.add("endDate", EndDate);
			if ("".equals(platname)) {
				model.add("platform", "PC");
			} else {
				model.add("platform", platname);
			}
			List<String> dateList = DateUtil.getDayList(StartDate, EndDate);
			List<String> keyresultList = new ArrayList<String>();
			for (String date : dateList) {
				String rowkeyPrefix = date + "::" + platname + "::" + clicktag;
				keyresultList.add(rowkeyPrefix);
			}

			resultlist = statisticsPlanService
					.QueryForListByPrefixForClickCity(keyresultList, wdzbSet,
							100);
			if ("".equals(selecttype))// 查询
			{
				Paginate<String> pList = new Paginate<String>(
						resultlist.size(), pageindex, 20, null);
				model.add("pList", pList);
				model.add("paramurl", url.toString());
				List<ClickCityVo> rslist = new ArrayList<ClickCityVo>();
				for (int i = (pageindex - 1) * 20; i < resultlist.size()
						&& i < pageindex * 20; i++) {
					rslist.add(resultlist.get(i));
				}
				model.add("rsList", rslist);
			} else // 下载
			{
				resultlist = statisticsPlanService
						.QueryForListByPrefixForClickCity(keyresultList,
								wdzbSet, 5000);
				ExcelUtil2<ClickCityVo> u = new ExcelUtil2<ClickCityVo>(
						ClickCityVo.class);
				u.setFieldFilter(cols);
				u.createExcelFileAndDownload(resultlist, excelTitle);
				return new ContentResult("");
			}
		} catch (Exception e) {
			e.printStackTrace();
			return new ContentResult("error");
		}
		return ActionResult.view("/Statistics/ClickCity");
	}

	/**
	 * 导流总流量查询
	 * 
	 * @author houzuoxin
	 * @return
	 */
	@Path("SourceAll")
	@POST
	@GET
	public ActionResult SourceAllBiData() {
		HttpServletRequest request = beat.getRequest();
		Model model = beat.getModel();
		try {
			/** 获取日期 */
			String StartDate = ServletRequestUtils.getStringParameter(request,
					"startDate", "");
			String EndDate = ServletRequestUtils.getStringParameter(request,
					"endDate", "");

			String platname = ServletRequestUtils.getStringParameter(request,
					"platform", "");
			/** 获取查询条件 */
			String PageTypeCombine = ServletRequestUtils.getStringParameter(
					request, "PageTypeCombine", "");
			String TwoPageTypeCombine = ServletRequestUtils.getStringParameter(
					request, "TwoPageTypeCombine", "");
			String cateOneCombine = ServletRequestUtils.getStringParameter(
					request, "cateOneCombine", "");
			String cateTwoCombine = ServletRequestUtils.getStringParameter(
					request, "cateTwoCombine", "");
			String PvIndex = ServletRequestUtils.getStringParameter(request,
					"PvIndex", "");
			String UvIndex = ServletRequestUtils.getStringParameter(request,
					"UvIndex", "");
			String sourcename = ServletRequestUtils.getStringParameter(request,
					"sourcename", "");
			/** 获取查询方式 */
			String selecttype = ServletRequestUtils.getStringParameter(request,
					"typename", "");
			/** 获取页码 */
			int pageindex = ServletRequestUtils.getIntParameter(request,
					"pageindex", 1);// 页数。
			List<String> cols = new ArrayList<String>();
			cols.add("statdate");
			cols.add("sourcename");
			String excelTitle = "后续总流量流量数据";
			StringBuffer url = new StringBuffer();// 分页的URL
			if ("".equals(StartDate) || "".equals(EndDate)) {
				model.add("platform", "PC");
				return ActionResult.view("/Statistics/SourceAll");
			}
			if ("".equals(platname)) {
				model.add("platform", "PC");
			} else {
				model.add("platform", platname);
			}
			model.add("startDate", StartDate);
			model.add("endDate", EndDate);
			model.add("sourcename", sourcename);
			url.append("&startDate=" + StartDate);
			url.append("&endDate=" + EndDate);
			url.append("&platform=" + platname);
			HashSet<String> wdzbSet = new HashSet<String>();
			if (!"".equals(PageTypeCombine)) {
				model.add("PageTypeCombine", PageTypeCombine);
				url.append("&PageTypeCombine=" + PageTypeCombine);
				cols.add("pagetype");
				wdzbSet.add("PageTypeCombine");
			}
			if (!"".equals(TwoPageTypeCombine)) {
				model.add("TwoPageTypeCombine", TwoPageTypeCombine);
				url.append("&TwoPageTypeCombine=" + TwoPageTypeCombine);
				cols.add("twopagetype");
				wdzbSet.add("TwoPageTypeCombine");
			}
			if (!"".equals(cateOneCombine)) {
				model.add("cateOneCombine", cateOneCombine);
				url.append("&cateOneCombine=" + cateOneCombine);
				cols.add("cate1");
				wdzbSet.add("cateOneCombine");
			}
			if (!"".equals(cateTwoCombine)) {
				model.add("cateTwoCombine", cateTwoCombine);
				url.append("&cateTwoCombine=" + cateTwoCombine);
				cols.add("cate2");
				wdzbSet.add("cateTwoCombine");
			}
			if (!"".equals(PvIndex)) {
				model.add("PvIndex", PvIndex);
				url.append("&PvIndex=" + PvIndex);
				cols.add("pv");
				wdzbSet.add("PvIndex");
			}
			if (!"".equals(UvIndex)) {
				model.add("UvIndex", UvIndex);
				url.append("&UvIndex=" + UvIndex);
				cols.add("uv");
				wdzbSet.add("UvIndex");
			}
			url.append("&sourcename=" + sourcename);
			List<ClickEventsSourceVo> resultlist = new ArrayList<ClickEventsSourceVo>();
			List<String> dateList = DateUtil.getDayList(StartDate, EndDate);
			List<String> keyresultList = new ArrayList<String>();
			for (String date : dateList) {
				String dateHash = "0" + Integer.parseInt(date) % 10;
				String rowkeyPrefix = dateHash + "::" + date + "::" + platname
						+ "::" + sourcename;
				keyresultList.add(rowkeyPrefix);
			}

			resultlist = statisticsPlanService
					.QueryForListByPrefixForSourceAll("LCSourceALL",
							keyresultList, wdzbSet, 100);
			if ("".equals(selecttype))// 查询
			{
				Paginate<String> pList = new Paginate<String>(
						resultlist.size(), pageindex, 20, null);
				model.add("pList", pList);
				model.add("paramurl", url.toString());
				List<ClickEventsSourceVo> rslist = new ArrayList<ClickEventsSourceVo>();
				for (int i = (pageindex - 1) * 20; i < resultlist.size()
						&& i < pageindex * 20; i++) {
					rslist.add(resultlist.get(i));
				}
				model.add("rsList", rslist);
			} else // 下载
			{
				resultlist = statisticsPlanService
						.QueryForListByPrefixForSourceAll("LCSourceALL",
								keyresultList, wdzbSet, 5000);
				ExcelUtil2<ClickEventsSourceVo> u = new ExcelUtil2<ClickEventsSourceVo>(
						ClickEventsSourceVo.class);
				u.setFieldFilter(cols);
				u.createExcelFileAndDownload(resultlist, excelTitle);
				return new ContentResult("");
			}
		} catch (Exception e) {
			e.printStackTrace();
			return new ContentResult("error");
		}
		return ActionResult.view("/Statistics/SourceAll");
	}

	/**
	 * 統計代碼
	 * 
	 * @author houzuoxin
	 * @return
	 */
	@Path("tongjidaima")
	@POST
	@GET
	public ActionResult tongjidaima() {

		return ActionResult.view("/Statistics/tongjidaima");

	}
	/**
	 * 使用幫助
	 * 
	 * @author houzuoxin
	 * @return
	 */
	@Path("HelpTips")
	@POST
	@GET
	public ActionResult HelpTipsController() {

		return ActionResult.view("/Statistics/HelpTips");

	}
	/**
	 * 冲突检测
	 * 
	 * @author houzuoxin 
	 * @return
	 */
	@Path("ConflictDelect")
	@POST
	@GET
	public ActionResult ConflictDelect() {
		HttpServletRequest request = beat.getRequest();
		Model model = beat.getModel();
		try {
			/** 获取日期 */
			
			String platname = ServletRequestUtils.getStringParameter(request,
					"platform", "");
			String selectcontent = ServletRequestUtils.getStringParameter(request,
					"selectcontent", "");
			String clicktag = ServletRequestUtils.getStringParameter(request,
						"clicktag", "");
			String pagetype = ServletRequestUtils.getStringParameter(request,
						"pagetype", "");
			String page = ServletRequestUtils.getStringParameter(request,
						"page", "");
			String pagetype1 = ServletRequestUtils.getStringParameter(request,
					"pagetype1", "");
			String page1 = ServletRequestUtils.getStringParameter(request,
						"page1", "");
			String source = ServletRequestUtils.getStringParameter(request,
					"source", "");
			/** 获取页码 */
			int pageindex = ServletRequestUtils.getIntParameter(request,
					"pageindex", 1);// 页数。
			String keystr="";
			List<String> cols = new ArrayList<String>();
			if(platname==""||selectcontent=="")
			{
				return ActionResult.view("/Statistics/ConflictDelect");
			}
			if("pagetype0name".equals(selectcontent))
			{ 
			  cols.add("pagetype");
			  cols.add("page");
			  keystr=platname+"::3"+"::"+pagetype+"::"+page.trim();
			}else if("pagetype1name".equals(selectcontent)){
			  cols.add("pagetype1");
			  cols.add("page1");
			  keystr=platname+"::4"+"::"+page1+"::"+pagetype1.trim();
			}else if("clicktagname".equals(selectcontent)){
			  cols.add("clicktag");
			  keystr=platname+"::1"+"::"+clicktag;
			}else if("sourcename".equals(selectcontent)){
			  cols.add("source");
			  keystr=platname+"::2"+"::"+source;
			}
			model.add("platform", platname);
			model.add("selectcontent", selectcontent);
			model.add("clicktag", clicktag);
			model.add("pagetype", pagetype);
			model.add("page", page);
			model.add("source", source);
			model.add("page1", page1);
			model.add("pagetype1", pagetype1);
			StringBuffer url = new StringBuffer();// 分页的URL
			url.append("&platform=" + platname);
			url.append("&selectcontent=" + selectcontent);
			url.append("&clicktag=" + clicktag);
			url.append("&pagetype=" + pagetype);
			url.append("&page=" + page);
			url.append("&source=" + source);
			url.append("&page1=" + page1);
			url.append("&pagetype1=" + pagetype1);
			cols.add("statdate");
			List<ConflictDelectVo> resultlist = new ArrayList<ConflictDelectVo>();
			resultlist = statisticsPlanService.QueryForListByPrefixForConflictDelect(
					keystr, 100);
			if(resultlist==null)
			{
				model.add("rsList", "");
			}else{
				Paginate<String> pList = new Paginate<String>(
						resultlist.size(), pageindex, 20, null);
				model.add("pList", pList);
				model.add("paramurl", url.toString());
				List<ConflictDelectVo> rslist = new ArrayList<ConflictDelectVo>();
				for (int i = (pageindex - 1) * 20; i < resultlist.size()
						&& i < pageindex * 20; i++) {
					rslist.add(resultlist.get(i));
				}
				model.add("rsList", rslist);
			}
		} catch (Exception e) {
			e.printStackTrace();
			return new ContentResult("error");
		}
		return ActionResult.view("/Statistics/ConflictDelect");
	}

}